@import '../../styles/variables.less';
@import '../../styles/antd-custom.less';

.chatContainer {
  display: flex;
  height: calc(100vh - 120px);
  min-height: 700px;
  background: linear-gradient(135deg, #f5f7ff 0%, #eef2ff 100%);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  position: relative;
  z-index: 10;
  backdrop-filter: blur(10px);
  transition: all 0.3s ease-in-out;

  &::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: radial-gradient(circle at 90% 10%, rgba(79, 70, 229, 0.15) 0%, transparent 60%),
                radial-gradient(circle at 10% 90%, rgba(16, 185, 129, 0.1) 0%, transparent 60%);
    z-index: -1;
    pointer-events: none;
  }
}

/* 侧边栏样式 */
.sideBar {
  width: 280px;
  border-right: 1px solid rgba(209, 213, 219, 0.5);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background-color: rgba(255, 255, 255, 0.8);
  padding: 20px;
  transition: all 0.3s ease-in-out;

  &::-webkit-scrollbar {
    width: 4px;
  }

  &::-webkit-scrollbar-track {
    background: transparent;
  }

  &::-webkit-scrollbar-thumb {
    background-color: rgba(156, 163, 175, 0.5);
    border-radius: 10px;
  }
}

/* 聊天列表 */
.chatList {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

/* 新建聊天按钮 */
.newChatButton {
  margin-bottom: 20px;
  width: 100%;
  height: 46px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 15px;
  background: linear-gradient(135deg, #4f46e5 0%, #818cf8 100%);
  border: none;
  color: white;
  box-shadow: 0 2px 5px rgba(79, 70, 229, 0.3);
  transition: all 0.2s ease-in-out;

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
    background: linear-gradient(135deg, #4338ca 0%, #6366f1 100%);
  }

  &:active {
    transform: translateY(0);
  }
}

/* 聊天项目样式 */
.chatItem {
  cursor: pointer;
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 2px;
  transition: all 0.2s ease-in-out;
  background-color: rgba(255, 255, 255, 0.5);
  border: 1px solid transparent;

  &:hover {
    background-color: rgba(249, 250, 251, 0.9);
    transform: translateX(4px);
    border-color: rgba(229, 231, 235, 0.8);
  }
}

.chatItemActive {
  cursor: pointer;
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 2px;
  background-color: rgba(79, 70, 229, 0.08);
  color: #4f46e5;
  border-left: 3px solid #4f46e5;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.1);
}

.chatItemContent {
  display: flex;
  align-items: center;
  overflow: hidden;
}

.chatItemInfo {
  flex: 1;
  overflow: hidden;
  margin-left: 10px;
}

.chatItemTitle {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chatItemMeta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 12px;
  color: #6b7280;
  margin-top: 4px;
}

.chatItemDate {
  flex-shrink: 0;
  margin-right: 4px;
}

.chatIcon {
  margin-right: 10px;
  font-size: 18px;
  color: #4f46e5;
}

/* [MOD] 添加聊天项删除按钮样式 */
.chatItemDeleteBtn {
  opacity: 0;
  transition: all 0.2s ease;
  padding: 0 6px;
  margin-left: 5px;
  line-height: 1;
  height: 24px;
  
  &:hover {
    background-color: rgba(220, 38, 38, 0.1);
    color: #f43f5e;
  }
}

.chatItem:hover .chatItemDeleteBtn,
.chatItemActive:hover .chatItemDeleteBtn {
  opacity: 0.7;
  
  &:hover {
    opacity: 1;
  }
}

/* 主聊天区域 */
.chatMain {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background-color: rgba(255, 255, 255, 0.9);
}

/* 消息区域 */
.messageBox {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background-image:
    radial-gradient(circle at 10% 20%, rgba(147, 197, 253, 0.05) 0%, transparent 50%),
    radial-gradient(circle at 90% 80%, rgba(167, 139, 250, 0.05) 0%, transparent 50%);

  &::-webkit-scrollbar {
    width: 6px;
  }

  &::-webkit-scrollbar-track {
    background: transparent;
  }

  &::-webkit-scrollbar-thumb {
    background-color: rgba(156, 163, 175, 0.3);
    border-radius: 10px;

    &:hover {
      background-color: rgba(156, 163, 175, 0.5);
    }
  }
}

/* 空聊天状态 */
.emptyChat {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #6b7280;
  padding: 0 40px;
  text-align: center;

  h3 {
    margin-top: 20px;
    margin-bottom: 12px;
    font-size: 24px;
    color: #374151;
  }

  p {
    font-size: 16px;
    max-width: 500px;
    line-height: 1.6;
    margin-bottom: 30px;
  }
}

.emptyChatIcon {
  font-size: 64px;
  margin-bottom: 20px;
  color: #4f46e5;
  background: linear-gradient(135deg, #4f46e5 0%, #818cf8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0% { transform: translateY(0px); }
  50% { transform: translateY(-10px); }
  100% { transform: translateY(0px); }
}

/* 消息列表 */
.messageList {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  position: relative;
}

/* 用户和AI消息样式 */
.userMessage,
.aiMessage {
  margin-bottom: 24px;
  max-width: 92%;
  position: relative;
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.userMessage {
  align-self: flex-end;
}

.aiMessage {
  align-self: flex-start;
}

.messageContent {
  padding: 16px;
  border-radius: 12px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  transition: all 0.3s ease;

  &:hover {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  }
}

.userMessage .messageContent {
  background: linear-gradient(135deg, #4f46e5 0%, #818cf8 100%);
  color: white;
  border: none;
}

.aiMessage .messageContent {
  background-color: white;
  border: 1px solid #e5e7eb;
}

.messageHeader {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  justify-content: space-between;
}

.messageHeader > :first-child,
.messageHeader > :nth-child(2) {
  margin-right: auto;
}

.messageSender {
  display: flex;
  align-items: center;
  gap: 8px;
}

.messageTime {
  color: #8c8c8c;
  font-size: 12px;
  margin-left: 8px;
  font-weight: normal;
}

.userMessage .messageTime {
  color: white;
}

.messageControls {
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.userMessage:hover .messageControls,
.aiMessage:hover .messageControls {
  opacity: 1;
}

.messageBadge {
  margin-right: 4px;
}

.messageBadge :global(.ant-badge-count) {
  background: linear-gradient(135deg, #4f46e5 0%, #818cf8 100%);
  box-shadow: 0 2px 5px rgba(79, 70, 229, 0.3);
}

.collapseButton {
  color: #9ca3af;
  font-size: 12px;
  padding: 0 4px;
  height: 22px;
  background: transparent;
  border: none;
  border-radius: 4px;

  &:hover {
    color: #4f46e5;
    background: rgba(79, 70, 229, 0.1);
  }
}

.userAvatar {
  background: linear-gradient(135deg, #4f46e5 0%, #818cf8 100%);
  margin-right: 8px;
  border: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 2px 5px rgba(79, 70, 229, 0.3);
}

.aiAvatar {
  background: linear-gradient(135deg, #059669 0%, #10b981 100%);
  margin-right: 8px;
  border: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 2px 5px rgba(16, 185, 129, 0.3);
}

.messageText {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
  font-size: 15px;
}

.userMessage .messageText {
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
}

/* 打字动画效果 */
.typingIndicator {
  display: inline-flex;
  align-items: center;

  span {
    width: 8px;
    height: 8px;
    margin: 0 2px;
    background-color: #9ca3af;
    border-radius: 50%;
    display: inline-block;
    animation: typing 1.4s infinite ease-in-out both;

    &:nth-child(1) {
      animation-delay: -0.32s;
    }

    &:nth-child(2) {
      animation-delay: -0.16s;
    }
  }
}

@keyframes typing {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* 输入区域 */
.inputArea {
  padding: 20px 24px;
  border-top: 1px solid rgba(229, 231, 235, 0.5);
  background-color: white;
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 12px;
  position: relative;
}

.topControls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.settingsButton {
  font-size: 20px;
  color: #4f46e5;
  background: rgba(79, 70, 229, 0.1);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;

  &:hover {
    color: white;
    background: #4f46e5;
    transform: rotate(30deg);
  }
}

.modelSelector {
  margin-bottom: 0;
  flex: 1;
  margin-right: 12px;
}

.modelSelector :global(.ant-select) {
  width: 100% !important;
  max-width: calc(100% - 50px);
}

.modelSelector :global(.ant-select-dropdown) {
  min-width: 280px !important;
  max-width: 350px !important;
}

.modelSelector :global(.ant-select-item) {
  padding: 8px 12px;
}

.modelSelector :global(.ant-select-item-option-content) {
  white-space: normal;
  word-break: break-word;
}

.modelSelector :global(.ant-select-selector) {
  height: auto !important;
  min-height: 42px;
  padding: 6px 12px !important;
  border-radius: 8px !important;
  border-color: #e5e7eb !important;
  box-shadow: none !important;
  transition: all 0.2s ease !important;
}

.modelSelector :global(.ant-select-focused .ant-select-selector) {
  border-color: #4f46e5 !important;
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.2) !important;
}

.modelSelector :global(.ant-select-selection-item) {
  padding: 4px 0 !important;
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  flex-wrap: nowrap !important;
  overflow: hidden !important;
}

.modelOption {
  display: flex;
  flex-direction: row;
  align-items: center;
  width: 100%;
  overflow: hidden;
}

.modelDescription {
  font-size: 12px;
  color: rgba(0, 0, 0, 0.45);
  margin-left: 8px;
  line-height: 1.5;
  white-space: normal;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: calc(100% - 100px);
}

.inputBox {
  display: flex;
  align-items: flex-end;
  background-color: white;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  padding: 6px;
  transition: all 0.2s ease;
  position: relative;

  &:focus-within {
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
  }
}

.inputBox :global(.ant-input) {
  border: none !important;
  box-shadow: none !important;
  padding: 8px 12px !important;
  font-size: 15px !important;
  padding-right: 50px !important; /* 为发送按钮留出空间 */
}

.inputBox :global(.ant-input:focus) {
  box-shadow: none !important;
}

.sendButton {
  position: absolute;
  right: 6px;
  bottom: 6px;
  height: 40px;
  width: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #4f46e5 0%, #818cf8 100%);
  border: none;
  box-shadow: 0 2px 5px rgba(79, 70, 229, 0.3);
  transition: all 0.2s ease;
  z-index: 2;

  &:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
  }

  &:active {
    transform: scale(0.95);
  }
}

.sendButton :global(.anticon) {
  font-size: 16px;
}

/* 思考内容样式 */
.thinkingWrapper {
  margin-bottom: 16px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;

  &:hover {
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.07);
  }
}

.thinkingHeader {
  padding: 10px 14px;
  background-color: rgba(243, 244, 246, 0.8);
  backdrop-filter: blur(5px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #e5e7eb;
}

.thinkingTitle {
  display: flex;
  align-items: center;
  gap: 6px;
}

.thinkingCard {
  margin-bottom: 0;
  background-color: rgba(249, 250, 251, 0.8);
  border-radius: 0;
  box-shadow: none;
}

.thinkingCard :global(.ant-card-body) {
  padding: 14px;
}

.thinkingContent {
  margin: 0;
  white-space: pre-wrap;
  font-family: 'JetBrains Mono', 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
  font-size: 13px;
  color: #374151;
  line-height: 1.5;
  border-radius: 8px;
  background-color: rgba(255, 255, 255, 0.6);
  padding: 10px;
}

/* 代码块样式 */
.codeBlockWrapper {
  margin: 12px 0;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.codeBlockHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background-color: #343a40;
  color: #e9ecef;
  font-family: 'JetBrains Mono', 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
  font-size: 12px;
}

.codeBlockLeft {
  display: flex;
  align-items: center;
}

.codeBlockHeader span {
  margin-left: 8px;
  text-transform: lowercase;
  font-weight: 500;
}

.codeBlockControls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.codeBlockButton {
  color: #e9ecef;
  opacity: 0.7;
  padding: 2px 6px;
  height: auto;
  transition: all 0.2s ease;
  
  &:hover {
    opacity: 1;
    color: white;
    background-color: rgba(255, 255, 255, 0.1);
  }
  
  &:focus {
    color: white;
  }
}

/* 回到顶部按钮 */
.scrollTopButton {
  position: fixed;
  right: 30px;
  bottom: 160px;
  z-index: 10;
  opacity: 0.7;
  transition: opacity 0.3s;

  &:hover {
    opacity: 1;
  }
}

.scrollTopButton :global(.anticon) {
  font-size: 18px;
  color: #4f46e5;
}

/* 单条消息回到顶部按钮 */
.messageTopButton {
  position: absolute;
  right: -30px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0;
  transition: all 0.3s;
  width: 28px;
  height: 28px;
  background-color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  border: none;

  &:hover {
    opacity: 1 !important;
    background-color: #4f46e5;
    box-shadow: 0 3px 10px rgba(79, 70, 229, 0.3);
    transform: translateY(-50%) scale(1.1);
  }
}

.messageTopButton:hover :global(.anticon) {
  color: white;
}

.messageTopButton :global(.anticon) {
  font-size: 14px;
  color: #4f46e5;
}

.aiMessage:hover .messageTopButton,
.userMessage:hover .messageTopButton {
  opacity: 0.7;
}

/* 参数设置样式 */
:global(.chat-settings-drawer .ant-drawer-header) {
  background: linear-gradient(135deg, #4f46e5 0%, #818cf8 100%);
  border-radius: 0;
  border-bottom: none;
}

:global(.chat-settings-drawer .ant-drawer-title) {
  color: white;
  font-weight: 600;
  font-size: 18px;
}

:global(.chat-settings-drawer .ant-drawer-close) {
  color: rgba(255, 255, 255, 0.85);
}

:global(.chat-settings-drawer .ant-drawer-close:hover) {
  color: white;
  background: rgba(255, 255, 255, 0.1);
}

:global(.chat-settings-drawer .ant-drawer-body) {
  background-color: rgba(249, 250, 251, 0.9);
  padding: 24px;
}

.settingsContent {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.settingItem {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;

  &:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08);
  }
}

.settingLabel {
  display: flex;
  flex-direction: column;
  margin-bottom: 4px;
}

.settingLabel strong {
  font-size: 16px;
  margin-bottom: 4px;
  color: #1f2937;
}

.settingLabel :global(.ant-typography-secondary) {
  font-size: 14px;
}

.sliderWithNumber {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sliderWithNumber :global(.ant-slider) {
  margin: 0;
}

.sliderWithNumber :global(.ant-slider-track) {
  background-color: #4f46e5;
}

.sliderWithNumber :global(.ant-slider-handle) {
  border-color: #4f46e5;
}

.sliderWithNumber :global(.ant-slider-handle:focus) {
  box-shadow: 0 0 0 5px rgba(79, 70, 229, 0.2);
}

.sliderWithNumber :global(.ant-input-number) {
  border-radius: 8px;
}

.sliderWithNumber :global(.ant-input-number-focused) {
  border-color: #4f46e5;
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.2);
}

.slider {
  flex: 1;
}

.errorMessage {
  padding: 8px 16px;
  margin-bottom: 16px;
  border-radius: 8px;
  max-width: 80%;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 16px;
  position: sticky;
  top: 0;
  z-index: 11;
}
